﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Windows.Markup;

namespace WpfTextSamples.VS2010Samples.Sample0001
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region MainWindow()

        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion

        #region Load(string fileName)

        private static FlowDocument Load(string fileName)
        {
            FlowDocument content;

            //using (var xamlFile = new FileStream(fileName, FileMode.Open, FileAccess.Read))

            Assembly assembly = Assembly.GetExecutingAssembly();
            if (assembly == null) return null;

            using (var xamlFile = assembly.GetManifestResourceStream(string.Format("WpfTextSamples.VS2010Samples.Sample0001.{0}", fileName)))
            {
                if (xamlFile == null) return null;

                try
                {
                    content = XamlReader.Load(xamlFile) as FlowDocument;
                }
                finally
                {
                    xamlFile.Close();
                }
            }

            return content;
        }

        #endregion

        #region ButtonPlain_Click(object sender, RoutedEventArgs e)

        private void ButtonPlain_Click(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentPlain.xaml");
        }

        #endregion

        #region ButtonMisc1_Click(object sender, RoutedEventArgs e)

        private void ButtonMisc1_Click(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentMisc1.xaml");
        }

        #endregion

        #region ButtonComplex1_OnClick(object sender, RoutedEventArgs e)

        private void ButtonComplex1_OnClick(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentComplex1.xaml");
        }

        #endregion

        #region ButtonRuby_Click(object sender, RoutedEventArgs e)

        private void ButtonRuby_Click(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentRuby.xaml");
        }

        #endregion

        #region ButtonSuperscript_Click(object sender, RoutedEventArgs e)

        private void ButtonSuperscript_Click(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentSuperscript.xaml");
        }

        #endregion

        #region ButtonSubscript_Click(object sender, RoutedEventArgs e)

        private void ButtonSubscript_Click(object sender, RoutedEventArgs e)
        {
            FlowDocumentPageViewer.Document = Load("FlowDocumentSubscript.xaml");
        }

        #endregion
    }
}
